package gameStates.absGamesStates.gui;

import logic.common.player.Player;
import logic.common.player.playerListeners.PlayerListener;
import logic.nodes.TeamNode;
import logic.ships.hunter.Hunter;
import main.listeners.listenerClasses.GameListener;
import gameStates.absGamesStates.AbsIngameState;
import gameStates.gui.GUIState;
import gameStates.passes.AbsPassManagerState;
import interfaces.hud.BasicHUD;
import interfaces.hud.chat.ChatType;
import interfaces.hud.pilot.PilotHUD;
import interfaces.hud.spectate.SpectateHUD;

public abstract class AbsHUDState extends GUIState {
	
	protected BasicHUD basicHUD;
	protected PilotHUD pilotHUD;
	protected SpectateHUD spectateHUD;
	protected BasicHUD currentHUD;
	
	protected AbsIngameState ingameState;
	
	public AbsHUDState(AbsIngameState ingameState, AbsPassManagerState passManagerState, boolean init) {
		super("hud", passManagerState, init);
		this.ingameState = ingameState;
		
		addListenerToClearer(new GameListener() {
			@Override
			public void gameStarted() {
				setActive(true);
			}
			
			@Override
			public void gameFinished() {
				setActive(false);
			}
			
			@Override
			public void gameDestroyed() {
				setActive(false);
			}
		});
	}
	
	public void init() {
		initHUDs();
		setHUD(spectateHUD);
	}
	
	protected abstract void setHUD(BasicHUD hud);
	
	public abstract void nextPlayer(boolean next);
	
	public PilotHUD getPilotHUD() { return pilotHUD; }
	
	public Player getWatchedPlayer() { return spectateHUD.getWatchedPlayer(); }
	
	public BasicHUD getCurrentHUD() { return currentHUD; }
	
	public AbsIngameState getIngameState() { return ingameState; }
	
	public boolean isSpectating() { return currentHUD == spectateHUD; }
	
	protected void initHUDs() {
		basicHUD = new BasicHUD(this);
		pilotHUD = new PilotHUD(this);
		spectateHUD = new SpectateHUD(this);
	}
	
	public abstract void registerTeamNode(TeamNode node);
	
	public abstract void unRegisterTeamNode(TeamNode node);
	
	public abstract PlayerListener getKillListener(final Player player);
	
	public abstract void showChatText(String text, ChatType type);
	
	public abstract void setSpectatedHUD();
	
	public abstract void changeMarkedTarget(Hunter newTarget);
}